package com.example.icongyou.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.icongyou.bean.Semester;
import java.util.List;

public class SemesterSpinnerAdapter extends ArrayAdapter<Semester> {

    public SemesterSpinnerAdapter(Context context, List<Semester> semesters) {
        super(context, android.R.layout.simple_spinner_item, semesters);
        setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    }

    @Override
    public @NonNull View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)  {
        View view = super.getView(position, convertView, parent);
        Semester semester = getItem(position);
        assert semester != null;
        ((TextView) view.findViewById(android.R.id.text1)).setText(semester.getSemesterName());
        return view;
    }

    @Override
    public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
        View view = super.getDropDownView(position, convertView, parent);
        Semester semester = getItem(position);
        assert semester != null;
        ((TextView) view.findViewById(android.R.id.text1)).setText(semester.getSemesterName());
        return view;
    }
}